/*
Kiwi Editor is a framework for building WYSIWYG web editors.
Copyright (C) 2011  Roosevelt de Lima Sardinha

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Contact the author at roosevelt1@gmail.com (Roosevelt) 
*/

/**
 * It manages the creation and remotion of profiles.
 * @author Roosevelt de Lima Sardinha
 * @constructor
 */
function profileManager(){	
	/**
	 * Creates a profile.
	 * @return The profile that was created.
	 * @type Object
	 */
	this.createProfile = function(){
		//Creates  a new Profile Object
		var myProfile = new profile();
		return myProfile;
	}

	/**
	 * Gets a profile by its given id.
	 * @param {Int} id The id of the profile.
	 * @return The profile that has the given id.
	 * @type {Object}
	 */
	this.get = function(id){
		// Returns a profile
		var myRequest = new request();
        myRequest.sendSincRequest('GET', null, "profiles/" + id, function(response){
            profileStr = response;
        });
		var profileJSON = JSON.parse(profileStr);
		var myProfile = new profile();
		
		myProfile.id = profileJSON.id;
		myProfile.name = profileJSON.name;
		myProfile.description = profileJSON.description;
		myProfile.types = profileJSON.type;
		
		return myProfile;
	}
	
	/**
	 * Gets all the profiles in the database.
	 * @return An object containing all the profiles
	 * @type {Object}
	 */	
	this.all = function(){
		// Returns all profiles
		var myRequest = new request();
        myRequest.sendSincRequest('GET', null, "profiles", function(response){
            profilesStr = response;
        });
		var profilesJSON = JSON.parse(profilesStr);
		
		return profilesJSON;
	}
	
	/**
	 * Removes a profile from the database by its id.
	 * @param {Int} id The id of the profile to be removed.
	 */
	this.remove = function(id){
		// Removes a profile by id
		var myRequest = new request();
		var params = [];
		params['_method'] = 'DELETE';
        myRequest.sendSincRequest('POST', params, "profiles/" + id, function(response){});
	}
}
